/* 引入jsencrypt实现数据RSA加密 */
import JSEncrypt from 'jsencrypt';// 处理长文本数据时报错 jsencrypt.js Message too long for RSA

import axios from '../api/axios';

export default {
    /* JSEncrypt加密 */
    async rsaPublicData(data) {
        let res = await axios.get("http://localhost:3000/login/getPublicKey");
        console.log(res);
        var jsencrypt = new JSEncrypt();
        jsencrypt.setPublicKey(res.publicKey)
        window.localStorage.setItem("public-Key", res.publicKey);
        // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
        var result = jsencrypt.encrypt(data);
        return result
    },
    // 修改密码的时候需要使用
    noTokenRsa(data) {
        var jsencrypt = new JSEncrypt();
        let publicKey = window.localStorage.getItem("public-Key");
        jsencrypt.setPublicKey(publicKey)
        // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
        var result = jsencrypt.encrypt(data);
        return result;
    }
}